<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <!--某些数据是基于之前数据实时计算出来的，我们可以利用计算属性-->
        <ul>
            <li>西游记的价格为：{{xyjPrice}}；数量为：{{xyjCount}}<input type="text" v-model="xyjCount"></li>
            <li>水浒传的价格为：{{shzPrice}}；数量为：{{shzCount}}<input type="text" v-model="shzCount"></li>
            <li>总价：{{totalPrice}}</li>
            {{msg}}
        </ul>
    </div>
    <script src="../node_modules/vue/dist/vue.js"></script>
    <script>
        new Vue({
            el:"#app",
            data:{
                xyjPrice:30,
                shzPrice:40,
                xyjCount:20,
                shzCount:30
            },
            computed:{
                totalPrice(){
                    return this.xyjPrice*this.xyjCount+this.shzPrice*this.shzCount
                }
            },
            watch:{
                xyjCount:function(newVal,oldVal){
                    alert("新值为："+newVal+"；旧值为："+oldVal);
                    if(newVal>3){
                        this.msg="库存超出限制"
                    }
                }
            }
        });
    </script>
</body>
</html>